import { httpService } from '@/utils/request'
import type {
    ChatSession,
    ChatDetail,
    ChatMessage,
    SendMessageRequest,
    SendMessageResponse
} from './models'

// 获取会话记录
export function getChatSessions(type: string = 'chat'): Promise<ChatSession[]> {
    return httpService.get<ChatSession[]>('/chat', { type })
}

// 获取对话详情
export function getChatDetail(chatId: string): Promise<ChatDetail> {
    return httpService.get<ChatDetail>(`/chat/${chatId}`)
}

// 发送消息
export function sendMessage(params: SendMessageRequest): Promise<SendMessageResponse> {
    const { chatId, content, isStream = false } = params
    return httpService.post<SendMessageResponse>(`/chat/completions${isStream ? '?stream=true' : ''}`, {
        chatId,
        content
    })
}

// 流式发送消息
export function sendMessageStream(params: SendMessageRequest): Promise<Response> {
    const { chatId, content } = params
    return fetch(`/api/chat/completions?stream=true`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            chatId,
            content
        })
    })
}

// 创建文件对话
export function createFileChat(data: { chatId: string; filename: string }): Promise<any> {
    return httpService.post('/file/chat/create', data)
} 